package inits

import (
	"fmt"
	"github.com/hashicorp/consul/api"
)

type ServiceConsul struct {
	ConsulAddr  string
	ServiceName string
	ServiceID   string
	ServiceHost string
	ServicePort int
	Tags        []string
}

func RegisterConsul(config ServiceConsul) string {

	configs := api.DefaultConfig()
	configs.Address = config.ConsulAddr
	_, err = api.NewClient(configs)
	if err != nil {
		panic("创建客户端实例失败")

	}
	registration := api.AgentServiceRegistration{
		Address: config.ConsulAddr,
	}
	sprintf := fmt.Sprintf("服务注册成功:%v", registration)
	return sprintf
}
